home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 001-100 / 001-025 / 024 / modula-2 / m2 / speechdemo.mod < prev    next >
Text File  |  1995-03-17  |  2KB  |  70 lines

  1. (********************************************************************************
  2.  
  3. Name         : SpeechDemo.MOD
  4. Version      : 1.0
  5. Purpose      : Demo using Translator and Narrator
  6. Author       : ms
  7. Modified     : 3.4.86  23:19 ms
  8.  
  9. ********************************************************************************)
  10.  
  11. MODULE SpeechDemo;
  12.  
  13. FROM Terminal   IMPORT BusyRead, Read, Write, WriteString, WriteLn;
  14. FROM Translator IMPORT Translate;
  15. FROM Narrator   IMPORT Narrate, NarrateErr;
  16.  
  17. CONST bs  = 10C;
  18.       lf  = 12C;
  19.       ff  = 14C;
  20.       cr  = 15C;
  21.       esc = 33C;
  22.       del =177C;
  23.       csi =233C;
  24.  
  25. VAR in, out: ARRAY [0..127] OF CHAR;
  26.     translateErr: LONGINT;
  27.     narrateErr: NarrateErr;
  28.  
  29. PROCEDURE ReadString(VAR st: ARRAY OF CHAR);
  30. VAR pos: CARDINAL; ch: CHAR;
  31. BEGIN
  32.   pos:=0;
  33.   LOOP
  34.     Read(ch);
  35.     IF (ch=cr) OR (ch=lf) THEN
  36.       IF pos<=HIGH(st) THEN st[pos]:=0C END; EXIT
  37.     ELSIF  ch=esc THEN
  38.       st[0]:=0C; EXIT
  39.     ELSIF ((ch=bs) OR (ch=del)) & (pos>0) THEN
  40.       Write(bs); Write(' '); Write(bs); DEC(pos);
  41.     ELSIF (ch>=' ') & (ch<del) & (pos<HIGH(st)) THEN
  42.       st[pos]:=ch; Write(ch); INC(pos)
  43.     ELSIF ch=csi THEN (* Command Sequence Introducer *)
  44.       REPEAT BusyRead(ch) UNTIL ch=0C (* Skip Command Sequence *)
  45.     END
  46.   END
  47. END ReadString;
  48.  
  49. BEGIN
  50.   WriteString('Translator & Narrator Demo'); WriteLn;
  51.   WriteString('=========================='); WriteLn; WriteLn;
  52.   in:='This is the first MODULA 2 program that speaks on the AMIGA!  ';
  53.   WriteString('text> '); WriteString(in); WriteLn;
  54.   LOOP
  55.     Translate(in, out, translateErr);
  56.     IF translateErr=0D THEN
  57.       WriteString('phon> '); WriteString(out); WriteLn;
  58.       Narrate(out, NIL, narrateErr);
  59.       IF narrateErr#ndOk THEN
  60.         WriteString('Narrator Returns Error'); WriteLn
  61.       END
  62.     ELSE
  63.       WriteString('Translator Returns Error'); WriteLn
  64.     END;
  65.     WriteLn;
  66.     WriteString('text> '); ReadString(in); WriteLn;
  67.     IF in[0]=0C THEN EXIT END
  68.   END (* LOOP *)
  69. END SpeechDemo.
  70.